package com.ikunikun.controller.user;

import com.ikunikun.dto.ShoppingCartDTO;
import com.ikunikun.entity.ShoppingCart;
import com.ikunikun.result.Result;
import com.ikunikun.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = "购物车相关接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

	@Resource
	private ShoppingCartService shoppingCartService;

	@ApiOperation("添加购物车")
	@PostMapping("/add")
	public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
		log.info("添加购物车，商品信息为：{}", shoppingCartDTO);
		shoppingCartService.addShoppingCart(shoppingCartDTO);
		return Result.success();
	}

	@ApiOperation("购物车查询")
	@GetMapping("/list")
	public Result<List<ShoppingCart>> list(){
		List<ShoppingCart> shoppingCarts = shoppingCartService.shoppingCart();
		return Result.success(shoppingCarts);
	}

	@ApiOperation("清空购物车")
	@DeleteMapping("/clean")
	public Result<String> clean(){
		shoppingCartService.clean();
		return Result.success("购物车清空成功");
	}
}
